package com.example.thread;

import java.util.concurrent.*;

/**
 * create by mwh 2021-11-16
 **/

public class Callableimp implements Callable<String> {
    int sum = 0;
    @Override
    public String call() throws Exception {

        for(int i=0;i<10;i++){
         sum ++;
        }
        System.out.println(Thread.currentThread().getName()+"**"+sum);
        return Thread.currentThread().getName();
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String result= null;
        FutureTask<String> future = new FutureTask(new Callableimp());
        new Thread(future).start();
        if(!future.isDone()){
            System.out.println("任务还没跑完");
        }
//        调用get()方法获取任务结果,如果任务没有执行完成则阻塞等待
        result =   future.get();
        System.out.println(Thread.currentThread().getName()+"mian========="+result);
    }

}
